package com.hzit.search.controller;

import com.hzit.search.service.ItemSearchService;
import com.hzit.search.vo.ItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.io.IOException;
import java.util.Map;

/**
 * 类名：
 * 作者：WF
 * 功能：搜索控制器
 */
@Controller
public class SearchController {

	@Autowired
	private ItemSearchService searchService;
	//1. 默认页面
	@GetMapping({"/","/search.html"})
	public String search(Model model, ItemVo vo) throws IOException {
		//1.1 开始搜索，返回map集合
		Map map = searchService.search(vo);
		//1.2 将查询得到的map放到model中
		model.addAttribute("resultMap",map);
		model.addAttribute("vo",vo);
		//1.3 返回视图
		return "search";
	}
}
